{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "dd7f11fa",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from tqdm import tqdm\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "import random, os, shutil\n",
    "from skimage.io import imread, imsave, imread_collection\n",
    "from skimage.transform import rotate, AffineTransform, warp\n",
    "from skimage.util import random_noise\n",
    "from skimage.filters import gaussian\n",
    "from skimage import exposure"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "9874ce12",
   "metadata": {},
   "outputs": [],
   "source": [
    "train = imread_collection(r'C:\\Users\\andre\\Desktop\\car-tagging\\complex\\*.jpg')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "5c57c70b",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 95/95 [05:09<00:00,  3.26s/it]\n"
     ]
    }
   ],
   "source": [
    "form = r\"C:\\Users\\andre\\Desktop\\car-tagging\\complex_oversampled\\{0}-{1}.jpg\"\n",
    "for i in tqdm(range(len(train))):\n",
    "    plt.imsave(form.format(i, \"original\"), train[i])\n",
    "    plt.imsave(form.format(i, \"rotated\"), rotate(train[i], angle=random.uniform(-45,45), mode = 'wrap'))\n",
    "    plt.imsave(form.format(i, \"flipped\"), np.fliplr(train[i]))\n",
    "    plt.imsave(form.format(i, \"noised\"), random_noise(train[i],var=0.2**2))\n",
    "    plt.imsave(form.format(i, \"blurred\"), gaussian(train[i],sigma=1,multichannel=True))\n",
    "    plt.imsave(form.format(i, \"sheared\"), warp(train[i], AffineTransform(shear=0.5), order=1, preserve_range=True, mode='wrap').astype(np.uint8))\n",
    "    plt.imsave(form.format(i, \"contrast\"), exposure.rescale_intensity(train[i], in_range=tuple(np.percentile(train[i], (0.2, 99.8)))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "74b461ee",
   "metadata": {},
   "outputs": [],
   "source": [
    "source = r'C:\\Users\\andre\\Desktop\\car-tagging\\balanced_mercedes'\n",
    "dest = r'C:\\Users\\andre\\Desktop\\car-tagging\\test'\n",
    "files = os.listdir(source)\n",
    "no_of_files = 220\n",
    "\n",
    "for file_name in random.sample(files, no_of_files):\n",
    "    shutil.move(os.path.join(source, file_name), dest)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7b92ce46",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "c7a650d791d0a1d035b66682f8967f04fed3045153a1ba3c3bfeefd2541b18a6"
  },
  "kernelspec": {
   "display_name": "conda_pytorch_p36",
   "language": "python",
   "name": "conda_pytorch_p36"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
